<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        Promise.any2=function(promises){
            return new Promise((resolve,reject)=>{
                if(!Array.isArray(promises))return reject(new TypeError('Argument is not iterable'))
                promises.length===0&& reject(new AggregateError(promises, "promises were rejected"))
                let count=0,errors=[]
                promises.forEach((p,index)=>{
                    Promise.resolve(p).then(res=>{
                        resolve(res)
                    },error=>{
                        count++
                        errors[index]=error
                        count===promises.length&&reject(new AggregateError(errors, "promises were rejected"))
                    })
                })
            })
        }
        const p=new Promise((resolve,reject)=>{
    // resolve('哈哈')
  
    // resolve('哈哈')
//   throw 'error2'
    reject('呜呜')
})
const p2=new Promise((resolve,reject)=>{
    reject(2)
})


Promise.any2([p,p2]).then(res=>{console.log(res)},error=>{
    console.log(error,'error');
})
    </script>
</body>
</html>